package com.nulldev.util.concurrency.threadIt.v4.emapi.testing;

import com.nulldev.util.JVM.JVM;
import com.nulldev.util.concurrency.threadIt.v4.emapi.ExecutorManager;
import com.nulldev.util.concurrency.threadIt.v4.emapi.extensions.IFutureTaskFlags;
import com.nulldev.util.concurrency.threadIt.v4.emapi.uft.Executable;
import com.nulldev.util.io.FastIO.FastIO;

public class FTPollingAPITest {

	public static void main(String[] args) {
		final Executable<Long> f = ExecutorManager.globalSubmit(() -> {
			try {
				Thread.sleep(10 * 1000L);
			} catch (InterruptedException e) {
			}
			long mul = 1L;
			for (int i = 2; i < 8; i++) {
				mul *= i;
			}
			return mul;
		});
		if ((int) f.getFlag(IFutureTaskFlags.FT_SUPPORTS_POLLING) != IFutureTaskFlags.FT_TRUE)
			throw new RuntimeException(
					"The Executable implementation does NOT support polling! [got: " + f.getFlag(IFutureTaskFlags.FT_SUPPORTS_POLLING) + "]");
		JVM.println("status: " + f.status());
		final Object x = f.pollUntilCompletion();
		JVM.println("x: " + x);
		FastIO.get().flush();
		JVM.exit();
	}

}
